package com.heima.tess4j;

import net.sourceforge.tess4j.ITesseract;
import net.sourceforge.tess4j.Tesseract;
import net.sourceforge.tess4j.TesseractException;

import java.io.File;

/**
 * @author tmh
 * @date 2023/8/22 16:36
 * @description
 */
public class Application {
    public static void main(String[] args) {

        try {
            //获取本地图片
            File file=new File("D:\\BaiduNetdiskDownload\\heimaHeadNews\\tessTest.jpg");
            //创建Tesseract对象
            ITesseract tesseract = new Tesseract();
            //设置字体库路径
            tesseract.setDatapath("D:\\BaiduNetdiskDownload\\heimaHeadNews\\tessdata");
            //中文识别
            tesseract.setLanguage("chi_sim");
            //执行ocr识别
            String result = tesseract.doOCR(file);
            //把所有的回车和tab替换为-
            System.out.println("执行结果为："+result.replaceAll("\\r|\\n","-"));
        } catch (TesseractException e) {
            e.printStackTrace();
        }

    }
}
